package danny.hoi.service.admin.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import danny.hoi.dao.export.admin.CompanyDao;
import danny.hoi.domain.export.admin.Company;
import danny.hoi.domain.export.admin.CompanyExample;
import danny.hoi.service.admin.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

/**
 * 企业crud服务提供商
 */
@Service(retries = 0)
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyDao companyDao;

    @Override
    public List<Company> findAll(CompanyExample example) {
        return companyDao.selectByExample(example);
    }

    @Override
    public PageInfo<Company> findByPages(CompanyExample example, Integer pageNum, Integer pageSize) {
        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<Company> companies = findAll(example);

        return new PageInfo<>(companies);
    }

    @Override
    public Company findById(String id) {
        return companyDao.selectByPrimaryKey(id);
    }


    @Override
    public void save(Company company) {
        //设置主键id
        company.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        companyDao.insertSelective(company);
    }

    @Override
    public void update(Company company) {
        companyDao.updateByPrimaryKeySelective(company);
    }

    @Override
    public void delete(String id) {
        companyDao.deleteByPrimaryKey(id);
    }
}
